<?php


require_once 'Objects/Chatlog.php';

/**
 * Makes chatlog objects.
 * @author DePhille
 *
 */
class ChatlogFactory {
	/**
	 * Builds a Chatlog Object from a Database Row.
	 * 
	 * @param databaseRow Asociative array representing the database row.
	 * @return A newly made Chatlog object.
	 */
	public function fromRow($databaseRow) {
		// Check if a valid row was given:
  		if (!is_array($databaseRow)) {
  			return NULL;
  		}
  		
  		// Make chatlog object:
  		$log = new ChatLog();
  		
		// Fill in protocol:
  		if (isset($databaseRow["protocol"])) {
  			$log->setProtocol($databaseRow["protocol"]);
  		}
  		
		// Fill in account:
  		if (isset($databaseRow["account"])) {
  			$log->setAccount($databaseRow["account"]);
  		}
  		
		// Fill in recipient:
  		if (isset($databaseRow["recipient"])) {
  			$log->setRecipient($databaseRow["recipient"]);
  		}
  		
		// Fill in startDate:
  		if (isset($databaseRow["startDate"])) {
  			$log->setStartDate($databaseRow["startDate"]);
  		}
  		
		// Fill in revision:
  		if (isset($databaseRow["revision"])) {
  			$log->setRevision($databaseRow["revision"]);
  		}
  		
		// Fill in contents:
  		if (isset($databaseRow["contents"])) {
  			$log->setContents($databaseRow["contents"]);
  		}
  		
  		// Return log:
  		return $log;		
	}
}
?>
